﻿using System;
using System.Windows.Data;
using System.Text;

namespace MDCAdminTool
{
    public class TimeSpanConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var sb = new StringBuilder(100);

            if (value is TimeSpan)
            {
                var ts = (TimeSpan)value;
                
                if (ts.Days > 0)
                    sb.AppendFormat(" D: {0:0,0}", ts.Days);
                if (ts.Hours > 0)
                    sb.AppendFormat(" H: {0:0,0}", ts.Hours);
                if (ts.Minutes > 0)
                    sb.AppendFormat(" M: {0:0,0}", ts.Minutes);
                if (ts.Seconds > 0)
                    sb.AppendFormat(" S: {0:0,0}", ts.Seconds);
            }
            return sb.ToString();
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}